package com.example.j280_webproject.day037;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

@WebServlet("/register01")
public class RegisterServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        int age = Integer.parseInt(req.getParameter("age"));

        resp.setContentType("text/html;charset=utf-8");
        PrintWriter writer = resp.getWriter();

        JDBC_Register jdbc_register = new JDBC_Register();
        try {
            boolean b = jdbc_register.register(username, password,age);
            if (b){
                writer.println("恭喜您！注册成功！");

            }else {
                writer.println("很遗憾！注册失败！");
            }
        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
            writer.print("系统繁忙，请稍后再试！");
        }
    }
}
